
#ifndef gettimeofday_h__
#define gettimeofday_h__


#ifdef WIN32
#include <WinSock2.h>

static
int gettimeofday (struct timeval *tv, void* tz)
{
    union { 
        LONGLONG ns100; /*time since 1 Jan 1601 in 100ns units */ 
        FILETIME ft; 
    } now; 
    GetSystemTimeAsFileTime (&now.ft);
    tv->tv_usec = (long) ((now.ns100 / 10LL) % 1000000LL); 
    tv->tv_sec = (long) ((now.ns100 - 116444736000000000LL) / 10000000LL); 
    return (0); 
}
#else
#include <sys/time.h>

#endif // WIN32


/** \brief tv2 - tv1 
 *
 */
static unsigned long long difftimeval( const struct timeval* tv1, const struct timeval* tv2 )
{
  return (unsigned long long) ( ( tv2->tv_sec - tv1->tv_sec)*1000+( tv2->tv_usec - tv1->tv_usec)/1000 );
}


#endif // gettimeofday_h__


